import os, sys
try:
    import openpyxl
except:
    os.system('pip3 install openpyxl')
    import openpyxl

def main(arg1):

    t3 = open(arg1, mode='r', encoding='utf16')
    v1 = t3.read()
    v2 = v1.split('\n')[1]
    v3 = v2.split(' ')
    # print(v3)

    t1 = openpyxl.Workbook()
    t2 = t1['Sheet']

    t4 = 'A'
    t5 = 2
    t6 = 'Z'
    t7 = t4
    for i2 in range(ord('A'), ord(t6)+1):
        t2.column_dimensions[chr(i2)].width = 4
    v_contents = {'A':'', 'B':'', 'C':''}

    for i1 in v3:
        if i1 != '.':
            if ord(t4) > ord(t6):
                t4 = t7
                t5 = t5 + 4
            for i3 in range(len(i1)//2):    #音节数
                #t_position = '%s%s' %(t4, ord(i1[i3*2]) - ord('A') + t5)
                v_contents[i1[i3*2]] = ''.join(map(str,(v_contents[i1[i3*2]], i1[i3*2+1])))
            for i4 in ['A', 'B', 'C']:
                t2[''.join(map(str,(t4, t5+ord(i4)-ord('A'))))] = v_contents[i4]
            v_contents = {'A':'', 'B':'', 'C':''}
            t4 = chr(ord(t4)+1)

    t1.save(os.path.basename(arg1)+'.xlsx')

if __name__ == "__main__":
    if len(sys.argv)>=2:
        main(sys.argv[1])
